package com.atguigu.eduservice.controller.controllerVo;


import com.atguigu.commonutils.Result;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.vo.CourseQueryVo;
import com.atguigu.eduservice.entity.vo.CourseWebVo;
import com.atguigu.eduservice.service.EduChapterService;
import com.atguigu.eduservice.service.EduCourseService;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduserviceFont/teacher_course_Info")
public class EduCourseControllerVo {
	@Resource
	private EduCourseService eduCourseService;

	@Resource
	private EduChapterService eduChapterService;

	@ApiOperation(value = "分页课程列表")
	@PostMapping(value = "{page}/{limit}")
	public Result pageList(
			@ApiParam(name = "page", value = "当前页码", required = true)
			@PathVariable Long page,

			@ApiParam(name = "limit", value = "每页记录数", required = true)
			@PathVariable Long limit,

			@ApiParam(name = "courseQuery", value = "查询对象", required = false)
			@RequestBody(required = false) CourseQueryVo courseQuery) {
		Page<EduCourse> pageParam = new Page<EduCourse>(page, limit);
		Map<String, Object> map = eduCourseService.pageListWeb(pageParam, courseQuery);
		return Result.ok().data(map);
	}


	@ApiOperation("单个课程详情")
	@GetMapping("/getFontcourseInfo/{courseId}")
	public Result getCourseById(@PathVariable String courseId) {
		/**
		 *  查出与从课程相关的所有信息-》包括课程的章节
		 */
		EduCourse course = eduCourseService.getById(courseId);
		List<CourseWebVo> chapterVoList = eduCourseService.getBaseCourseInfo(courseId);
		return Result.ok().data("course", course).data("chapterVoList", chapterVoList);
	}


}




